/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package minemapgenerator;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import util.GameSettings;

/**
 *
 * @author CodeBlue
 */
// create custom button
public class MyButton extends JButton implements ActionListener {

    // each button has a coordinate
    private Point point;
    // number of bombs arround (-1 means bomb)
    private int bombArround = 0;

    public MyButton(String text) {
        super(text);
        // button's shape is square
        setPreferredSize(new Dimension(GameSettings.BUTTON_SIZE, GameSettings.BUTTON_SIZE));
        setFont(new Font("Tahoma", 1, 15));
        setForeground(Color.blue);
        // add action when button is  clicked
        addAction();
    }

    public final void addAction() {
        addActionListener(this);
    }

    public Point getPoint() {
        return point;
    }

    public void setPoint(Point point) {
        this.point = point;
    }

    public int getBombArround() {
        return bombArround;
    }

    public void setBombArround(int bombArround) {
        this.bombArround = bombArround;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        bombArround = bombArround == 0 ? -1 : 0;
        if (bombArround == -1) {
            setText("");
            setIcon(new ImageIcon(getClass().getResource("/images/bomb.png")));
        } else {
            setText(" ");
            setIcon(null);
        }
    }
}
